package com.jasperframework.boot.common.enums;

import org.apache.commons.collections4.map.ListOrderedMap;

import java.util.EnumSet;

/**
  * <p> 文件下载格式 </p>
  *
  * @site https://miliqkdoc.motopa.cn/
  * @author daizhao
  * @date 2022/12/12 12:12
  */
public enum DownloadFileFormatEnum {

    TXT("txt", ".txt"),

    RAR("rar", ".rar"),

    APK("APK", ".apk"),

    XLS("XLS", ".xls"),

    ZIP("zip", ".zip");

    private final String code;

    private final String suffix;

    public String getCode()
    {
        return code;
    }

    public String getSuffix()
    {
        return suffix;
    }

    DownloadFileFormatEnum(String code, String suffix) {
        this.code = code;
        this.suffix = suffix;
    }

    public static final ListOrderedMap<String, String> enumMap = new ListOrderedMap<>();
    static {
        for (DownloadFileFormatEnum s : EnumSet.allOf(DownloadFileFormatEnum.class)) {
            enumMap.put(s.code, s.suffix);
        }
    }

    public static DownloadFileFormatEnum get(String code) {
        for (DownloadFileFormatEnum type : values()) {
            if (type.code.equalsIgnoreCase(code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 根据value获取desc
     * @param value
     * @return
     */
    public static String getDesc(String value) {
        for (DownloadFileFormatEnum type : DownloadFileFormatEnum.values()) {
            if (type.getCode().equalsIgnoreCase(value)) {
                return type.getSuffix();
            }
        }
        return "";
    }

    public static void main(String[] args) {
        System.out.println("DownloadFileFormateEnum.enumMap.toString() = " + DownloadFileFormatEnum.enumMap);
    }
}
